package main

import (
	"fmt"
)

func f1() int {
	x := 5
	defer func() {
		x++
	}()
	return x
}

func f2() (x int) {
	defer func() {
		x++
	}()
	return 5
}

func f3() (y int) {
	x := 5
	defer func() {
		x++
	}()
	return x
}
func f4() (x int) {
	defer func(x int) {
		x++
	}(x)
	return 5
}


// 匿名结构体嵌套，需要在声明的时候再写一遍，很麻烦
type student struct{

    name string
    gender string
    age int
    child []struct{
        name string
        age int
        gender string
        haveSchool bool
    }
}

func useStu(){

    stu := student{
        name: "john",
        gender: "male",
        age: 30,
        child: []struct{
            name string
            age int
            gender string
            haveSchool bool
        }{
            {
                name: "lobbie",
                age: 5,
                gender: "male",
                haveSchool: false,
            },
            {
                name: "mary",
                age: 2,
                gender: "female",
                haveSchool: true,
            },
        },
    }
    fmt.Printf("student %+v\n", stu)

}

type echoSpeaker interface{
    echo()
}
type demo struct{}
func (d demo)echo(){}

// check is valid
var _ echoSpeaker = demo{}
var _ echoSpeaker = &demo{}

func main() {
    useStu()
	fmt.Println(f1())
	fmt.Println(f2())
	fmt.Println(f3())
	fmt.Println(f4())
}
